package com.ejuornal.action;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.ejuornal.bean.Page;
import com.ejuornal.bean.SysMsg;
import com.ejuornal.service.SysMsgService;
import com.ejuornal.util.StrToIntArray;
@Component("sysMsgAction")
@Scope("prototype")
public class SysMsgAcion extends BaseAction<SysMsg>{
    private static final long serialVersionUID = 1790701962494491572L;
    private SysMsgService sysMsgService;
    private SysMsg sysMsg;
    private String  id1;
    private Map<String, Object> dataMap = new HashMap<String, Object>();
    private String url_1;
    private Page<SysMsg> pages;

	public String add() {
        sysMsgService.add(sysMsg);
        return SUCCESS;
    }
    
    public String list() {
        String url ="admin/sysMsgList";
        pages = sysMsgService.findByDate(page, url);
        return SUCCESS;
    }
    
    /**
     * Title:findByStatus
     * Description:是否读过
     * @return
     * String
     */
    public String findByStatus() {
        String status = super.getRequest().getParameter("status");
        int user_id = super.getUserIdBySession();
        if(user_id == -1 || status == null) {
        	return ERROR;
        }
        String url="";
        pages = sysMsgService.findByStatus(status, user_id, (page - 1) * 10, url);
        if(status.equals("1")) {
        	url = "/space/sysmsg_list_1.jsp";
        } else {
        	url = "/space/sysmsg_list_0.jsp";
        }
        return SUCCESS;
    }
    
    public String Detail() {
        int smId = Integer.parseInt((String)super.getRequestParameter("id"));
        sysMsg = sysMsgService.Detail(smId);
        return SUCCESS;
    }
	public String deleteSyString()
	{
		sysMsgService.delete(StrToIntArray.ChangeStrToIntArray(id1));
		return  SUCCESS;
	}
	
	public String isSysMsgHasNew() {
	    int user_id = super.getUserIdBySession();
	    if(sysMsgService.findNew(user_id) == true){
	        dataMap.clear();
	        dataMap.put("yes_2", "1");
	        return SUCCESS;
	    }
	    dataMap.clear();
        dataMap.put("yes_2", "0");
        return SUCCESS;
	}
	
	public String detail() {
		int messageId = super.getRequestParameter();
		if(messageId == -1) {
			return ERROR;
		}
		sysMsg = sysMsgService.findById(messageId);
		return SUCCESS;
	}
	
    public SysMsg getSysMsg() {
        return sysMsg;
    }
    public void setSysMsg(SysMsg sysMsg) {
        this.sysMsg = sysMsg;
    }
    public SysMsgService getSysMsgService() {
        return sysMsgService;
    }
    @Resource(name="sysMsgService")
    public void setSysMsgService(SysMsgService sysMsgService) {
        this.sysMsgService = sysMsgService;
    }

	public String getId1() {
		return id1;
	}

	public void setId1(String id1) {
		this.id1 = id1;
	}
    
	 public Map<String, Object> getDataMap() {
	        return dataMap;
	    }

    public void setDataMap(Map<String, Object> dataMap) {
        this.dataMap = dataMap;
    }
    
    public String getUrl_1() {
		return url_1;
	}

	public void setUrl_1(String url_1) {
		this.url_1 = url_1;
	}
	public Page<SysMsg> getPages() {
		return pages;
	}

	public void setPage(Page<SysMsg> pages) {
		this.pages = pages;
	}
}
